package com.seveneight.baijiesteward.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.bean.RankBean;
import com.seveneight.baijiesteward.http.HttpConfig;
import com.seveneight.baijiesteward.utils.GlideLoader;
import com.seveneight.baijiesteward.utils.UIHeperUtil;
import com.seveneight.baijiesteward.views.cover.FancyCoverFlow;
import com.seveneight.baijiesteward.views.cover.FancyCoverFlowAdapter;

import java.util.List;

/**
 * Created by user1 on 2018/2/12.
 */

public class LevelAdapter extends FancyCoverFlowAdapter {

    private LayoutInflater inflater;
    private Context context;
    private List<RankBean> data;
    int item1W = 0;
    int item2W = 0;

    public LevelAdapter(Context context, List<RankBean> data) {
        this.data = data;
        this.context = context;
        inflater = LayoutInflater.from(context);
        item1W = (int) (UIHeperUtil.getWindowWidth(context) * 0.35);
        item2W = (int) (item1W * 0.6);
    }

    @Override
    public View getCoverFlowItem(int position, View reusableView, ViewGroup parent) {
        ViewHolder holder = null;
        FancyCoverFlow.LayoutParams mLayoutParams = null;
        RankBean rankBean = data.get(position);
        if (reusableView == null) {
            holder = new ViewHolder();
            reusableView = inflater.inflate(R.layout.item_level,
                    null);
            holder.iv_level = reusableView.findViewById(R.id.iv_level);
            GlideLoader.displayImg(context, HttpConfig.SOURCE_URL + rankBean.getIcoUrl(), holder.iv_level);
            mLayoutParams = new FancyCoverFlow.LayoutParams(item1W, item1W);
            reusableView.setLayoutParams(mLayoutParams);
        }
        return reusableView;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return HttpConfig.SOURCE_URL+data.get(position).getIcoUrl();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private class ViewHolder {
        ImageView iv_level;
    }

}
